#!/usr/bin/env bash
#
# Copyright (c) Guangdong Big Banian Info Tech Co., Ltd. All rights reserved.
# 主要完成软件包(".deb")安装完成后所需的配置工作.
# 通常, postinst 脚本要求用户输入, 和/或警告用户如果接受默认值, 应该记得按要求返回重新配置这个软件. 一个软件包安装或升级完成后,postinst 脚本驱动命令, 启动或重起相应的服务.
#

prefix=@prefix@
pkg_name=@PACKAGE_NAME@
pgm_user=@pgm_user@
pgm_group=@pgm_group@

# Create startup link
update-rc.d -f ${pkg_name} remove
update-rc.d ${pkg_name} defaults

# If pgm_user and pgm_group does not exist, will then create pgm_user and pgm_group 
if ! [ $(getent group $pgm_user) ]; then
    useradd $pgm_user
fi


# Change dir user and group
if [ -d ${prefix}/${pkg_name} ]; then
    chown ${pgm_user}:${pgm_group} -R ${prefix}/${pkg_name}
    chmod 777 -R ${prefix}/${pkg_name}
fi

# Startup services
if [ -x /etc/init.d/${pkg_name} ]; then
    /etc/init.d/${pkg_name} start
fi

exit 0
